package com.yonyou.pmclouds.completedcatalog.processor;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.runtime.RuntimeEnvironment;
import com.yonyou.pmclouds.completedcatalog.entity.CompletedCatalogVO;
import com.yonyou.pmclouds.completedcollate.entity.CompletedCollateVO;
import com.yonyou.pmclouds.completedcollate.mapper.CompletedCollateVOMapper;

import java.util.List;

/**
 * 竣工资料目录删除时引用校验
 *
 * @author yzx
 * @Date: 2018/5/30 16:21
 */
public class CompletedCatalogDelCheck implements SingleProcessor<CompletedCatalogVO> {
    private CompletedCollateVOMapper collateVOMapper;

    public CompletedCatalogDelCheck(CompletedCollateVOMapper collateVOMapper) {
        this.collateVOMapper = collateVOMapper;
    }

    @Override
    public void process(CompletedCatalogVO vo, CompletedCatalogVO orig) throws BusinessException {
        // 通过资料目录pk，查询是否在引用资料中存在，被引用则不能删除
        List<CompletedCollateVO> collateVOList = collateVOMapper.queryByCatalogPk(vo.getPkCompletedCatalog(), RuntimeEnvironment.getTenantId());
        if (collateVOList.size() > 0) {
            throw new BusinessException("该目录已被引用,不能删除!");
        }
    }
}
